<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateHouseTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */

    public function up()
    {
      $table = $this->table('houses'); // 房源主表
      $table->setId('id')
            ->setEngine('InnoDB')
            ->addColumn('title', 'string', [])
            ->addColumn('keywords', 'string', ['default' => '', 'comment' => '关键字'])
            ->addColumn('thumb', 'string', ['default' => '', 'comment' => '缩略图'])
            ->addColumn('price', 'decimal', ['precision' => '14', 'scale' => '2', 'comment' => '总价'])
            ->addColumn('structure_type', 'integer', ['comment' => '户型'])
            ->addColumn('acreage', 'float', ['precision' => '8', 'scale' => '2', 'comment' => '面积'])
            ->addColumn('univalent', 'float', ['precision' => '8', 'scale' => '2', 'comment' => '每平价格'])
            ->addColumn('years', 'integer', ['comment' => '购买年份'])
            ->addColumn('decoration_type', 'integer', ['comment' => '装修类型'])
            ->addColumn('direction', 'string', ['comment' => '朝向'])
            ->addColumn('property_year', 'integer', ['comment' => '产权'])
            ->addColumn('purpose', 'integer', ['comment' => '用途'])
            ->addColumn('estate_name', 'string', ['comment' => '小区名'])
            ->addColumn('floor', 'string', ['comment' => '楼层'])
            ->addColumn('floor_type', 'string', ['comment' => '楼层类型'])
            ->addColumn('address', 'string', ['comment' => '地址'])
            ->addColumn('two_tax', 'string', ['comment' => '两税'])
            ->addColumn('tax_bear_type', 'string', ['comment' => '税务承担'])
            ->addColumn('arrears', 'boolean', ['comment' => '是否拖欠'])
            ->addColumn('video_address', 'string', ['comment' => '视频地址'])
            ->addColumn('position', 'string', ['comment' => '位置坐标'])
            ->addColumn('brokerage', 'float', ['precision' => '8', 'scale' => '2', 'comment' => '百分比佣金'])
            ->addColumn('reward', 'float', ['precision' => '8', 'scale' => '2', 'comment' => '奖励'])
            ->addColumn('created_at', 'datetime')
            ->addColumn('update_at', 'datetime')
            ->addIndex('keywords')
            ->addIndex('title')
            ->addIndex('keywords')
            ->addIndex('price')
            ->addIndex('structure_type')
            ->addIndex('acreage')
            ->addIndex('univalent')
            ->addIndex('years')
            ->addIndex('decoration_type')
            ->addIndex('property_year')
            ->addIndex('purpose')
            ->addIndex('estate_name')
            ->addIndex('floor_type')
            ->create();

      $tableb = $this->table('house_data'); // 房源附表
      $tableb->setId('id')
             ->setEngine('InnoDB')
             ->addColumn('house_id', 'integer', ['comment' => '对应房源id'])
             ->addColumn('content', 'text', ['comment' => '正文'])
             ->addColumn('slides', 'text', ['default' => '', 'comment' => '幻灯片图片'])
             ->addColumn('position_picture', 'text', ['comment' => '位置图片'])
             ->addIndex('house_id', ['unique' => true])
             ->create();
    }

    public function down() {
      $this->dropTable('houses');
      $this->dropTable('house_data');
    }
}
